package com.guowen.myaccount;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;

import com.google.android.material.tabs.TabLayout;
import com.guowen.myaccount.adapter.RecordPagerAdapter;
import com.guowen.myaccount.adapter.SortRagerAdapter;
import com.guowen.myaccount.frag_record.IncomeFragment;
import com.guowen.myaccount.frag_record.OutcomeFragment;
import com.guowen.myaccount.frag_sort.InSortFragment;
import com.guowen.myaccount.frag_sort.OutSortFragment;

import java.util.ArrayList;
import java.util.List;

public class SortActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sort);

        tabLayout = findViewById(R.id.sort_tabs);
        viewPager = findViewById(R.id.sort_vp);

        initPager();
    }

    private void initPager() {
        List<Fragment> fragments = new ArrayList<>();

        // 创建页面，放置在Fragment当中。
        OutSortFragment outFrag = new OutSortFragment();
        InSortFragment inFrag = new InSortFragment();
        fragments.add(outFrag);
        fragments.add(inFrag);

        // 创建适配器
        SortRagerAdapter sortRagerAdapter = new SortRagerAdapter(getSupportFragmentManager(),fragments);

        // 设置适配器
        viewPager.setAdapter(sortRagerAdapter);
        // 将TabLayout和ViewPager进行关联
        tabLayout.setupWithViewPager(viewPager);
    }


    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.activity_sort_back:
                finish();
                break;
        }
    }
}